package com.mes.basicdata.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

/**
 * <p>
 * 表示工艺和工序的一对多关系，不是网络，顺序关系。
 * </p>
 * 
 * <p>
 * Created on 2017-03-16
 * </p>
 * 
 * @author lcs
 * 
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "B_ROUTINE_OPER")
@BatchSize(size=30)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class RoutingOperation extends BasicModel implements
		java.io.Serializable {
	
	@Id
	@GenericGenerator(name = "uuid", strategy = "assigned")
	@Column(name="uniqueid",scale=0)
	private String uuid;

	// 工序排序号
	@Column(name="OPERATION_ID",precision=10, scale=2 )
	private Float operationId;

	// 工艺编号
	@Column(name="ROUTING")
	private String routingUid;
	// 工艺
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ROUTING",insertable=false,updatable=false)
	private Routing routing;
	
	// 工序编号
	@Column(name="OPUID")
	private String operationUid;
	// 工序
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="OPUID",insertable=false,updatable=false)
	private Operation operation;

	
	public RoutingOperation(String routingUid, String operationUid,
			Float operationId) {
		super();
		this.routingUid = routingUid;
		this.operationUid = operationUid;
		this.operationId = operationId;
	}
	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.uuid;
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.uuid = uuid;
	}
	
	public RoutingOperation() {
	}

	public Float getOperationId() {
		return operationId;
	}

	public void setOperationId(Float operationId) {
		this.operationId = operationId;
	}

	public Routing getRouting() {
		return routing;
	}

	public void setRouting(Routing routing) {
		this.routing = routing;
		this.routingUid=(routing!=null)?routing.getUuid():null;
	}

	public Operation getOperation() {
		return operation;
	}

	public void setOperation(Operation operation) {
		this.operation = operation;
		this.operationUid=(operation!=null)?operation.getUuid():null;
	}

	public String getRoutingUid() {
		return routingUid;
	}

	public void setRoutingUid(String routingUid) {
		this.routingUid = routingUid;
	}

	public String getOperationUid() {
		return operationUid;
	}

	public void setOperationUid(String operationUid) {
		this.operationUid = operationUid;
	}
/*
	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof RoutingOperation))
			return false;
		RoutingOperation castOther = (RoutingOperation) other;

		return ((this.getRoutingUid() == castOther.getRoutingUid()) || (this
				.getRoutingUid() != null
				&& castOther.getRoutingUid() != null && this.getRoutingUid()
				.equals(castOther.getRoutingUid())))
				&& ((this.getOperationUid() == castOther.getOperationUid()) || (this
						.getOperationUid() != null
						&& castOther.getOperationUid() != null && this
						.getOperationUid().equals(castOther.getOperationUid())));
	}

	public int hashCode() {
		int result = 17;

		result = 37
				* result
				+ (getRoutingUid() == null ? 0 : this.getRoutingUid()
						.hashCode());
		result = 37
				* result
				+ (getOperationUid() == null ? 0 : this.getOperationUid()
						.hashCode());
		return result;
	}
	*/



}